package com.jbt.mds.obdsdk;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NumberAdapter extends BaseAdapter {
    private Context mContext;
    private int[] numbers;

    public NumberAdapter(Context c, int[] numbers) {
        mContext = c;
        this.numbers = numbers;
    }

    @Override
    public int getCount() {
        return numbers.length;
    }

    @Override
    public Object getItem(int position) {
        return numbers[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView result;
        if (convertView == null) { // 如果没有可重用的视图
            result = new TextView(mContext);
            result.setText("Item "+position);
            result.setTextColor(Color.BLACK);
            result.setTextSize(24);
            result.setLayoutParams(new AbsListView.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)));
            result.setGravity(Gravity.CENTER);
            result.setBackgroundColor(Color.WHITE); //设置背景颜色
        } else {
            result = (TextView) convertView;
        }
        result.setText(String.valueOf(numbers[position]));
        return result;
    }
}